<script setup>
const props = defineProps({
  merchant: {
    type: Object,
    default: () => ({
      id: null,
      image: '',
      merchantName: '',
      location: '',
      merchantRating: 0,
      ratingCount: 0,
      businessMealsType: 0,
      status: 1,
    })
  }
})

// 跳转到店铺详情页
const goToMerchantDetail = () => {
  if (props.merchant.id) {
    uni.navigateTo({
      url: `/pages/ShopDetail/index?id=${props.merchant.id}`
    })
  }
}
</script>

<template>
  <view class="shop-item-container" @tap="goToMerchantDetail">
    <view class="shop-img-wrapper">
      <image
        :src="merchant.image || '/static/images/random-default.png'"
        alt="Shop Image"
        class="shop-image"
        mode="aspectFill"
      />
      <view class="shop-badge">
        <text class="iconfont icon-reliang"></text>
      </view>
    </view>
    <view class="shop-details">
      <view class="shop-header">
        <text class="shop-name">{{ merchant.merchantName || merchant.name || '未知店铺' }}</text>
        <view class="shop-rating">
          <text class="iconfont icon-icon"></text>
          <text class="rating-score">{{ (merchant.merchantRating ?? merchant.rating ?? 0).toFixed ? (merchant.merchantRating ?? merchant.rating ?? 0).toFixed(1) : (merchant.merchantRating ?? merchant.rating ?? 0) }}</text>
        </view>
      </view>

      <view class="shop-meta">
        <text class="shop-location" v-if="merchant.location">
          <text class="iconfont icon-weizhi"></text>
          {{ merchant.location }}
        </text>
      </view>

      <view class="shop-footer">
        <view class="shop-stats">
          <text class="sales-info"> 评价数 {{ merchant.ratingCount || 0 }} </text>
        </view>
      </view>
    </view>
  </view>
</template>

<style scoped lang="scss">
.shop-item-container {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 40rpx;
  box-shadow: 0 16rpx 64rpx rgba(0, 0, 0, 0.1);
  border: 2rpx solid rgba(255, 255, 255, 0.2);
  overflow: hidden;
  transition: all 0.3s ease;

  &:active {
    transform: translateY(-16rpx);
    box-shadow: 0 24rpx 80rpx rgba(0, 0, 0, 0.15);
    border-color: rgba(102, 126, 234, 0.3);
  }
}

.shop-img-wrapper {
  width: 100%;
  height: 360rpx;
  position: relative;
  overflow: hidden;
  background: #f5f7fa;

  .shop-image {
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease;
  }

  .shop-badge {
    position: absolute;
    top: 24rpx;
    right: 24rpx;
    background: linear-gradient(45deg, #ff6b6b, #ff8e8e);
    color: white;
    padding: 12rpx 20rpx;
    border-radius: 24rpx;
    font-size: 24rpx;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8rpx;
    box-shadow: 0 4rpx 16rpx rgba(255, 107, 107, 0.3);

    .iconfont {
      font-size: 24rpx;
    }
  }
}

.shop-details {
  padding: 40rpx;
  flex: 1;
}

.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24rpx;
  gap: 24rpx;

  .shop-name {
    font-size: 36rpx;
    font-weight: 600;
    color: #333;
    margin: 0;
    flex: 1;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.3;
  }

  .shop-rating {
    display: flex;
    align-items: center;
    gap: 8rpx;
    background: rgba(255, 193, 7, 0.1);
    padding: 8rpx 16rpx;
    border-radius: 16rpx;
    flex-shrink: 0;

    .iconfont {
      color: #ffc107;
      font-size: 28rpx;
    }

    .rating-score {
      font-size: 28rpx;
      font-weight: 600;
      color: #ffc107;
    }
  }
}

.shop-meta {
  display: flex;
  align-items: center;
  gap: 32rpx;
  font-size: 28rpx;
  color: #666;
  margin-bottom: 24rpx;
  flex-wrap: wrap;

  .shop-location {
    display: flex;
    align-items: center;
    gap: 8rpx;

    .iconfont {
      color: #667eea;
      font-size: 28rpx;
    }
  }
}

.shop-description {
  font-size: 28rpx;
  color: #666;
  line-height: 1.5;
  margin: 0 0 32rpx 0;
  opacity: 0.9;
  display: block;
}

.shop-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 16rpx;
  margin-bottom: 32rpx;

  .tag-item {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    padding: 8rpx 24rpx;
    border-radius: 24rpx;
    font-size: 24rpx;
    font-weight: 500;
    border: 2rpx solid rgba(102, 126, 234, 0.2);
    transition: all 0.3s ease;
  }
}

.shop-footer {
  border-top: 2rpx solid rgba(102, 126, 234, 0.1);
  padding-top: 32rpx;

  .shop-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 26rpx;
    color: #666;

    .sales-info,
    .price-info {
      display: flex;
      align-items: center;
      gap: 8rpx;
    }
  }
}
</style>
